<?php
// 本文档自动生成，仅供测试运行
class LoginUserAction extends ColorBabyCommonAction
{

	/**
	 * 需要限制用户安全访问，如果用户未登陆，则不能访问该页面
	 * Enter description here ...
	 */
	public function index(){
		
		//如果已登陆
		if(Session::is_set(C('USER_AUTH_KEY'))){			
			$commonCondition['type'] = $_REQUEST ['type'] ; 
			$commonCondition['user'] = Session::get(C('USER_AUTH_KEY')) ;
			$this->blogCommonQuery("blog",$commonCondition);
			$this->assign("type",$_REQUEST ['type']);
			$this->display() ;
		}
		//未登陆的情况
		else{
			$this->redirectWhenNotLogin();
		}
	}

	
	public function blogCommonQuery($table,$condition){
		$Dao = M($table);
		// 计算总数
		$count = $Dao->where($condition)->count();
		// 导入分页类
		import("ORG.Util.Page");
		// 实例化分页类
		$p = new Page($count, 10);
		// 分页显示输出
		$page = $p->show();
		// 当前页数据查询
		$list = $Dao->where($condition)->order('createdate desc')->limit($p->firstRow.','.$p->listRows)->select();		
		// 赋值赋值
		$this->assign('page', $page);
		$this->assign('list_info', $list);
	}
	
	/**
	 * 禁止评论或者打开评论
	 * Enter description here ...
	 */
	public function disableComment(){
		$id = $_REQUEST ['id'];
		$Dao = M("blog");
		$condition['id'] = $id;
		$list = $Dao->where($condition)->find() ;
		if($list['commentright']==0){
			$data['commentright'] = 1;
		}else{
			$data['commentright'] = 0;
		}
		// 更新的条件
		$condition['id'] = $id;
		$result = $Dao->where($condition)->save($data);
		if($result !== false){
			$this->assign("jumpUrl","__URL__/index/type/blog");
			$this->success("更新成功！") ;
		}else{
			$this->success("更新失败！" . $Dao.getError ()) ;
		}
	}






}
?>